home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / programming / e / lsestuff / msg.e < prev    next >
Text File  |  1999-11-29  |  2KB  |  88 lines

  1. OPT MODULE
  2.  
  3. MODULE 'exec/nodes', 'exec/ports'
  4.  
  5.  
  6. EXPORT OBJECT msg
  7.    mn:mn
  8.    command:LONG ->anything user wants
  9.    data:LONG  -> data ..
  10.    error:LONG ->positive values = user error
  11.               ->negative values = do error
  12.               ->zero = no error :)
  13. ENDOBJECT
  14.  
  15.  
  16. EXPORT PROC doMsgQName(portname, command, data=NIL)
  17.    DEF port
  18.    ->Forbid()
  19.    port:=FindPort(portname)
  20.    IF port THEN doMsgQ(port, command, data)
  21.    ->Permit()
  22. ENDPROC port
  23.  
  24. EXPORT PROC doMsgQ(toport, command, data=NIL)
  25.    DEF msg:PTR TO msg, er
  26.    NEW msg
  27.    doMsg(toport, msg, command, data)
  28.    er:=msg.error
  29.    END msg
  30. ENDPROC er
  31.  
  32. EXPORT PROC doMsgQF(toport, replyport, command, data=NIL)
  33.    DEF msg:PTR TO msg, er
  34.    NEW msg
  35.    doMsgF(toport, msg, replyport, command, data)
  36.    er:=msg.error
  37.    END msg
  38. ENDPROC er
  39.  
  40. EXPORT PROC doMsgName(portname, msg, command, data=NIL)
  41.    DEF port
  42.    Forbid()
  43.    port:=FindPort(portname)
  44.    IF port THEN doMsg(port, msg, command, data)
  45.    Permit()
  46. ENDPROC port
  47.  
  48. EXPORT PROC doMsg(toport, msg:PTR TO msg, command, data=NIL)
  49.    DEF replyport
  50.    replyport:=CreateMsgPort()
  51.    IF replyport = NIL THEN RETURN NIL
  52.    doMsgF(toport, msg, replyport, command, data)
  53.    DeleteMsgPort(replyport)
  54. ENDPROC msg
  55.  
  56.  
  57. EXPORT PROC doMsgF(toport, msg:PTR TO msg, replyport, command, data=NIL)
  58.    msg.mn.ln.type:=NT_MESSAGE
  59.    msg.mn.length:=SIZEOF msg
  60.    msg.mn.replyport:=replyport
  61.    msg.command:=command
  62.    msg.data:=data
  63.    msg.error:=NIL
  64.    PutMsg(toport, msg)
  65.    WaitPort(msg.mn.replyport)
  66.    WHILE GetMsg(replyport) DO GetMsg(replyport)
  67. ENDPROC msg
  68.  
  69. EXPORT PROC waitMsg(port)
  70.    DEF msg
  71.    WaitPort(port)
  72.    msg:=GetMsg(port)
  73. ENDPROC msg
  74.  
  75. EXPORT PROC emptyPort(port)
  76.    WHILE GetMsg(port)
  77.       ReplyMsg(port)
  78.    ENDWHILE
  79. ENDPROC
  80.  
  81. EXPORT PROC getLastMsg(port)
  82.    DEF msg, lastmsg=NIL
  83.    WHILE (msg:=GetMsg(port))
  84.       IF lastmsg THEN ReplyMsg(lastmsg)
  85.       lastmsg:=msg
  86.    ENDWHILE
  87. ENDPROC lastmsg
  88.